{% extends "admin/change_form.html" %}
{% load i18n admin_urls static admin_modify %}
 
{% block extrahead %}{{ block.super }}
<script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>
    <script>
        django.jQuery(function() {
            /* var select = django.jQuery("#id_{{ForeignKey名称}}"); */
            var select = django.jQuery("#id_a");
            select.change(function(){
                i = django.jQuery(this).val()
                var url = "{% url 'Demo:get_b' %}"
                django.jQuery.post(
                    url,
                    { id: i},
                    function(e){
                        var target = django.jQuery("#id_b");
                        target.empty();//先要清空一下
                        target.append('<option value>'+'---------'+'</option>');
                        django.jQuery.each(e,function(i,val){
                            target.append('<option value="'+val.id+'">'+val.name+'</option>')
                        });
                    });
                });
        });

        django.jQuery(function() {
            var select = django.jQuery("#id_b");
            select.change(function(){
                i = django.jQuery(this).val()
                var url = "{% url 'Demo:get_c' %}"
                django.jQuery.post(
                    url,
                    { id: i},
                    function(e){
                        var target = django.jQuery("#id_c");
                        target.empty();//先要清空一下
                        target.append('<option value>'+'---------'+'</option>');
                        django.jQuery.each(e,function(i,val){
                            target.append('<option value="'+val.id+'">'+val.name+'</option>')
                        });
                    });
                });
        });

    </script>
{#{{ media }}#}
{% endblock %}